//
// Created by wangjunjun on 2024/2/19.
//function：
//

#ifndef LOG_H
#define LOG_H
#include "log4cpp/PropertyConfigurator.hh"

#include "log4cpp/Appender.hh"
#include "log4cpp/Category.hh"
#include "log4cpp/Layout.hh"
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include "json.h"
#include <memory>
#include <mutex>
#define LOG_DEBUG(logEvent) \
{ \
        std::string s = __FILE__;\
        s += " : ";\
        std::stringstream line;\
        line << __LINE__;\
        s += line.str();\
        s += " : ";\
        std::ostringstream  buf ;\
        buf<< logEvent ;\
        s += buf.str();\
        CLog::GetInstance()->logDebug(s);\
};

#define LOG_ERROR(logEvent) \
{ \
        std::string s = __FILE__;\
        s += " : ";\
        std::stringstream line;\
        line << __LINE__;\
        s += line.str();\
        s += " : ";\
        std::ostringstream  buf ;\
        buf<< logEvent ;\
        s += buf.str();\
        CLog::GetInstance()->logError(s);\
};

#define LOG_INFO(logEvent) \
{ \
        std::string s = __FILE__;\
        s += " : ";\
        std::stringstream line;\
        line << __LINE__;\
        s += line.str();\
        s += " : ";\
        std::ostringstream  buf ;\
        buf<< logEvent ;\
        s += buf.str();\
        CLog::GetInstance()->logInfo(s);\
};

#define LOG_WARN(logEvent) \
{ \
        std::string s = __FILE__;\
        s += " : ";\
        std::stringstream line;\
        line << __LINE__;\
        s += line.str();\
        s += " : ";\
        std::ostringstream  buf ;\
        buf<< logEvent ;\
        s += buf.str();\
        CLog::GetInstance()->logWarn(s);\
};


#define LOG_FATAL(logEvent) \
{ \
        std::string s = __FILE__;\
        s += " : ";\
        std::stringstream line;\
        line << __LINE__;\
        s += line.str();\
        s += " : ";\
        std::ostringstream  buf ;\
        buf<< logEvent ;\
        s += buf.str();\
        CLog::GetInstance()->logFatal(s);\
};

#define LOG_DATA1(logEvent) \
{ \
        std::string s = __FILE__;\
        s += " : ";\
        std::stringstream line;\
        line << __LINE__;\
        s += line.str();\
        s += " : ";\
        std::ostringstream  buf ;\
        buf<< logEvent ;\
        s += buf.str();\
        CLog::GetInstance()->dataCapture1(s);\
};
class  CLog{
public:
    //instances
    //static  ILogManager* GetInstance();
    //    static  CLog* instance() ;
    static std::shared_ptr<CLog> GetInstance() ;
    //logDebug
    //param[in] strMsg : 消息
    void logDebug(const std::string & strMsg);

    //logError
    //param[in] strMsg : 消息
    void logError(const std::string & strMsg);

    //logInfo
    //param[in] strMsg : 消息
    void logInfo(const std::string & strMsg);

    //logWarn
    //param[in] strMsg : 消息
    void logWarn(const std::string & strMsg);

    //logFatal
    //param[in] strMsg : 消息
    void logFatal(const std::string& strMsg);

    /// <summary>
    /// 特殊状态保存接口
    /// </summary>
    /// <param name="strMsg"></param>
    void dataCapture1(const std::string& strMsg);

private:
    CLog();
    ~CLog();

private:
    std::string m_strConfigPath;
    Json::Value m_jsnConfig;
    static std::shared_ptr<CLog> m_pInstance;
    static std::once_flag mflag;
};


#endif //WRTELEMTRY_LOG_H
